package com.example.demo.java8;

import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;
import sun.applet.Main;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author f_bao
 * @create 2018/8/28
 */
public class LocalDateDemo {

    @Test
    public void localDateTest() throws Exception {

        int abs = Math.abs(1);
        System.out.println(abs);

        Date one = DateUtils.parseDate("2014-03-24 00:00:00", "yyyy-MM-dd HH:mm:ss");
        Date two = DateUtils.parseDate("2014-03-29 00:00:00", "yyyy-MM-dd HH:mm:ss");

        System.out.println(one.getTime());

        long difference =  (one.getTime()-two.getTime())/86400000;
        System.out.println(Math.abs(difference));

    }


    @Test
    public void teaaaa() throws Exception {

        Pattern compile = Pattern.compile("梦想旅行|APP|app|wifi|mafengwo|旅行翻译官|ctrip|蚂蜂窝|蜂|hotel|bnb|行程助手|穷游锦囊|TA|booking|airbnb|百度旅游|同程|途牛|马蜂窝|蜂首|穷游|qyer|Qyer|艺龙|去哪网|驴妈妈|众信旅游|到到网|tripAdvisor|春秋|Agoda|AV|子弹|证|猫途鹰|微信|微博|公众号|性交易|赌场|推荐|1234567890|http|租车|付款|电话|手机|淘宝|三亚|海鲜|微信|购买|投诉|团购|海鲜加工|师傅|天猫|按摩|大保健", Pattern.CASE_INSENSITIVE);
        Matcher matcher = compile.matcher("梦想旅行|APP|app|wifi|mafengwo|旅行翻译官|ctrip|蚂蜂窝|蜂|hotel|bnb");
        while (matcher.find()) {
            System.out.println(matcher.group());
        }

    }

    @Test
    public void teaaa() throws Exception {


        String s = "<h5 id=\"title4\" class=\"title5\">D5:遵义自驾到赤水，午餐后游览佛光岩景区，漫步丙安古镇，宿丙安古镇；<br></h5>".replaceAll("<[^>]+>", "");

        System.out.println(s);
    }

    @Test
    public void testbbb() {

        boolean equals = "携程攻略".equals(null);
        System.out.println(equals);

        List<Person> list = new ArrayList<>();
        list.add(new Person(1, "鱼丸"));

        Optional<Person> map = list.stream().filter(Objects::nonNull).findFirst();

        Boolean aBoolean = map.map(value -> value.equals("鱼丸")).orElse(false);

        System.out.println(aBoolean);

    }

    @Test
    public void testccc() {

        Date date = new Date(System.currentTimeMillis() + 86400000);

        System.out.println(com.example.demo.java8.DateUtils.toYMD(date));

    }

    @Test
    public void eststaa() {
        Person p = new Person();

        p.setName(null);

        System.out.println(p);


        Integer aa = null;

        BigDecimal bigDecimal = new BigDecimal(aa);

    }

    @Test
    public void syncTest() {
        Integer aa = null;
        switch (aa) {
            case 1:
                System.out.println("aa");
                break;
        }
    }



    public static void main(String[] args) {

        Person p1 = new Person();
        p1.setDate(new Date());
        p1.setId(1);

        Person p2 = new Person();
        p2.setDate(new Date(2000));
        p2.setId(2);

        Person p3 = new Person();
        p3.setDate(new Date(3000));
        p3.setId(3);

        List<Person> listPerson = new ArrayList<>();
        listPerson.add(p1);
        listPerson.add(p3);
        listPerson.add(p2);

        listPerson.stream().forEach(c -> {
            CompletableFuture.runAsync(() -> setPerson(c));
        });

        listPerson.forEach(person -> {
            System.out.println(person);
        });

    }

    public static void setPerson(Person person) {
        person.setName(Thread.currentThread().getName() + "person Name");
    }

    /**
     * 根据耗时分钟数计算 耗时
     * @param durationMinutes
     * @return
     */
    public static String buildFlightTimeConsume(int durationMinutes) {
        int hour = durationMinutes / 60;
        int minute = durationMinutes - (hour * 60);

        if (hour > 0 && minute > 0) {
            return "约" + hour + "小时" + minute + "分";
        } else if (hour > 0 && minute == 0) {
            return "约" + hour + "小时";
        } else if (minute > 0) {
            return "约" + minute + "分钟";
        }
        return null;
    }


    public static String getWifiDetailAPPUrl(String cityName) {
        try {


            String wifiAppUrl = "ctrip://wireless/h5?url=%s&type=1";
            String realUrl = "activity/index.html#/wifilist?keyword=%s&pshowcates=48&target=wifi";


            System.out.println(String.format(realUrl, cityName));


            return String.format(wifiAppUrl, Base64.getEncoder().encodeToString(String.format(realUrl, cityName).getBytes("utf-8")));
        } catch (UnsupportedEncodingException e) {
            return "";
        }
    }

}
